/**
 * 
 */
package co.fitstart.entity.order;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import com.demo2do.core.utils.Alias;

/**
 * 
 * @author mohanlan
 *
 */
@Alias("orderStatus")
public enum OrderStatus {
    
    CREATED("created", "已下单", "success", "created"),
    
    PENDING("pending", "待排课", "warning", "pending"),
    
    PROCESSING("processing", "授课中", "warning", "processing"),
    
    COMPLETE("compelte", "已完成", "danger", "closed"),
    
    CANCELED("canceled", "已取消", "default", "closed"),
    
    SHIPPING("shipping", "待发货", "", "shipping"),
    
    SHIPPED("shipped", "已发货", "", "shipped"),
    
    REFUNDED("refunded", "已退款", "default", "refunded"),
    
    HOLD("hold", "已冻结", "", "hold");
    
    private String alias;

    private String description;

    private String css;
    
    private String same;
    
    /**
     * @param alias
     * @param description
     * @param css
     */
    OrderStatus(String alias, String description, String css, String same) {
        this.alias = alias;
        this.description = description;
        this.css = css;
        this.same = same;
    }
    
    /**
     * 
     * @param alias
     * @return
     */
    public static OrderStatus aliasOf(String alias) {
        for(OrderStatus orderStatus : OrderStatus.values()) {
            if(orderStatus.getAlias().equalsIgnoreCase(alias)){
                return orderStatus;
            }
        }
        return null;
    }
    
    /**
     * get same orderStatus
     * 
     * @param same
     * @return
     */
    public static List<OrderStatus> sameAs(String same) {
        List<OrderStatus> result = new ArrayList<OrderStatus>();
        if(StringUtils.equalsIgnoreCase(same, "closed")) {
            result.add(OrderStatus.COMPLETE);
            result.add(OrderStatus.CANCELED);
        } else {
            if(aliasOf(same) != null) {
                result.add(aliasOf(same));
            }
        }
        
        return CollectionUtils.isEmpty(result) ? null : result;
    }
   
    /**
     * @return boolean OrderStatus equals COMPLETE or not
     */
    public boolean isComplete(){
    	return this.equals(COMPLETE);
    }
    
    /**
     * 
     * @return
     */
    public boolean couldEditPrice() {
        return !this.equals(COMPLETE) && !this.equals(CANCELED) && !this.equals(REFUNDED);
    }
    
    /**
     * 
     * @return
     */
    public boolean couldEditRefundPrice() {
        return this.equals(REFUNDED);
    }
    
    /**
     * @return the alias
     */
    public String getAlias() {
        return alias;
    }

    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * @return the css
     */
    public String getCss() {
        return css;
    }
    
    /**
     * 
     * @return the same
     */
    public String getSame() {
        return same;
    }
    
}
